package com.woniu;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ConcurrentModificationException;

/**
 * @author: 16327
 * @date: 2020/12/28 14:23
 * @description:
 */
@Component
public class ExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        System.out.println("进入异常解析器");
        if (ex instanceof NullPointerException){
            System.out.println("空指针");
        }else if (ex instanceof ArrayIndexOutOfBoundsException){
            new ModelAndView("a");
        }else if (ex instanceof ConcurrentModificationException){
            new ModelAndView("b");
        }else {
            System.out.println("其他异常");
        }
        return new ModelAndView("c");

    }
}
